﻿@using Hotel.Application;
@model QueryDto
@{
    Layout = null;
}
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layuiAdmin 内容系统 - 文章列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="~/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="~/layuiadmin/style/admin.css" media="all">
    <style type="text/css">
    .layui-form-item .layui-input-inline{
        width: 188px;
        margin-right: -32px;
    }    
    </style>
</head>
<body>

    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">关键字</label>
                        <div class="layui-input-inline">
                            <input asp-for="Keywords" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">开始时间</label>
                        <div class="layui-input-inline">
                            <input type="text" asp-for="StartTime" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">结束时间</label>
                        <div class="layui-input-inline">
                            <input type="text" asp-for="EndTime" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>

            <div class="layui-card-body">
                <table id="data-list" lay-filter="data-list"></table>
                <script type="text/html" id="table-content-list">
                    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
                </script>
            </div>
        </div>
    </div>

    <script src="~/lib/jquery/dist/jquery.min.js"></script>
    <script src="~/layuiadmin/layui/layui.js"></script>
    <script>
        layui.config({
            base: '/layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'contlist', 'table', 'laydate'], function () {
            var table = layui.table
                , form = layui.form;
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#StartTime' //指定元素
            });
            //执行一个laydate实例
            laydate.render({
                elem: '#EndTime' //指定元素
            });

            //监听搜索
            form.on('submit(LAY-app-contlist-search)', function (data) {
                var field = data.field;

                //执行重载
                table.reload('data-list', {
                    where: field
                });

                return false;
            });

            //第一个实例
            table.render({
                elem: '#data-list'
                , url: '@Url.Action("ToPageList",new{TypeId=ViewContext.RouteData.Values["Id"]})' //数据接口
                , page: true //开启分页
                , toolbar: 'default'
                , cols: [[ //表头
                    { width: 80, type: "checkbox" }
                    , { field: 'DicName', align: 'center', title: '字典名' }
                    , { field: 'DicValue', align: 'center', title: '字典值' }
                    , { field: 'DicCode', align: 'center', title: '字典编码' }
                    , { field: 'DicOrder', align: 'center', title: '字典排序' }
                    , { field: 'CreateName', hide:true, align: 'center', title: '创建人', sort: true }
                    , { field: 'CreateTime', hide: true, align: 'center', title: '创建时间' }
                    , { fixed: 'right', title: "操作", width: 150, align: 'center', toolbar: '#table-content-list' }
                ]]
            });

            //触发事件
            table.on('toolbar(data-list)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id);

                switch (obj.event) {
                    case 'add':
                        parent.layer.open({
                            type: 2
                            , title: '添加字典'
                            , content: '@Url.Action("Create",new{id=ViewContext.RouteData.Values["Id"]})'
                            , maxmin: true
                            , area: ['450px', '335px']
                            //, offset: ['36%', '42%']
                            , btn: ['确定', '取消']
                            , yes: function (index, layero) {
                                //点击确认触发 iframe 内容中的按钮提交
                                var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                                submit.click();
                            }
                        });
                        break;
                    case 'delete':
                        layer.confirm('真的删除行么', function (index) {
                            //向服务端发送删除指令
                            $.ajax({
                                url: "@Url.Action("Delete")",
                                type: "delete",
                                data: { entities: checkStatus.data },
                                success: function (e) {
                                    //执行重载
                                    table.reload('data-list');
                                    layer.close(index);
                                }
                            });
                        });
                        break;
                    case 'update':
                        if (checkStatus.data.length > 1 || checkStatus.data.length <= 0) {
                            layer.msg("只能选择一条记录", { icon: 5 });
                            return;
                        }
                        parent.layer.open({
                            type: 2
                            , title: '编辑字典'
                            , content: '@Url.Action("Edit")/' + checkStatus.data[0].DicId
                            , maxmin: true
                            , area: ['450px', '400px']
                            , btn: ['确定', '取消']
                            , yes: function (index, layero) {
                                //点击确认触发 iframe 内容中的按钮提交
                                var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                                submit.click();
                            }
                        });
                        break;
                };
            });

            //工具条事件
            table.on('tool(data-list)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
                var data = obj.data; //获得当前行数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）

                if (layEvent === 'detail') { //查看
                    //do somehing
                } else if (layEvent === 'del') { //删除
                    layer.confirm('真的删除行么', function (index) {
                        $.ajax({
                            url: "@Url.Action("Delete")",
                            type: "get",
                            data: { id: data.DicId },
                            success: function (e) {
                                obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                                layer.close(index);
                            }
                        });
                    });
                } else if (layEvent === 'edit') { //编辑
                    parent.layer.open({
                        type: 2
                        , title: '编辑字典'
                        , content: '@Url.Action("Edit")/' + data.DicId
                        , maxmin: true
                        , area: ['450px', '400px']
                        , btn: ['确定', '取消']
                        , yes: function (index, layero) {
                            //点击确认触发 iframe 内容中的按钮提交
                            var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                            submit.click();
                        }
                    });
                }
            });
        });
    </script>
</body>
</html>

